import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Login from '../views/Login.vue'
import Index from '../views/index.vue'
import Daojishi from '../views/daojishi.vue'
import Zhuyemian from '../views/zhuyemian.vue'
import show from '../views/show.vue'
import scroll from '../views/scroll.vue'
import look from '../views/look.vue'
import tongjitu from '../views/tongjitu.vue'
import test from '../views/test.vue'
import xiuxi from '../views/xiuxi.vue'
import choice from '../views/choice.vue'
import End from '../views/end'
import ChangCi from '../views/changci'


Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'Login',
        component: Login
    },
    {
        path: '/scroll',
        name: 'scroll',
        component: scroll
    },
    {
        path: '/look',
        name: 'look',
        component: look
    },
    {
        path: '/show',
        name: 'show',
        component: show
    },
    {
        path: '/choice',
        name: 'choice',
        component: choice
    },
    {
        path: '/tongji',
        name: 'tongjitu',
        component: tongjitu
    },
    {
        path: '/',
        name: 'test',
        component: test
    },
    {
        path: '/about',
        name: 'about',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: function() {
            return import ( /* webpackChunkName: "about" */ '../views/AboutView.vue')
        }
    },
    {
        path: '/index',
        name: 'index',
        component: Index
    },
    {
        path: '/daojishi',
        name: 'daojishi',
        component: Daojishi,
    },
    {
        path: '/zhuyemian',
        name: 'zhuyemian',
        component: Zhuyemian,
    },
    {
        path: '/xiuxi',
        name: 'xiuxi',
        component: xiuxi,
    },
    {
        path: '/end',
        name: 'end',
        component: End
    },
    {
        path: '/changci',
        name: 'changci',
        component: ChangCi
    }
]



const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    if (to.path === '/') return next()
    const tokenStr = window.sessionStorage.getItem('token')
    if (!tokenStr) return next('/')
    next()
})

export default router
